package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.DTResponseDto;
import com.hualude.roadsign.dto.JsonMsgDto;
import com.hualude.roadsign.service.CoverFaultService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by pjn on 2017/8/11.
 */
@Controller
@RequestMapping("/rds_coverFault")
public class CoverFaultController {
    @Resource
    private CoverFaultService coverFaultService;

    @RequestMapping(value = "/getCoverReportFault4DT")
    @ResponseBody
    public DTResponseDto getCoverReportFault4DT(DTRequestDto dtRequestDto, Integer actorId, Integer userId, Integer orgId) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = coverFaultService.getCoverReportFault4DT(dtRequestDto, actorId, userId, orgId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping(value = "/getCoverInfo2Fault")
    @ResponseBody
    public JsonMsgDto getCoverInfo2Fault(Integer coverId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(coverFaultService.getCoverInfo2Fault(coverId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getCoverFaultInfo2Fault")
    @ResponseBody
    public JsonMsgDto getCoverFaultInfo2Fault(Integer coverId, Integer coverFaultId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(coverFaultService.getCoverFaultInfo2Fault(coverId, coverFaultId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/updateCoverFault")
    @ResponseBody
    public JsonMsgDto updateCoverFault(Integer coverFaultId, Integer coverFaultLevel, Integer coverFaultType, String coverFaultPhoto, String coverFaultReason, Double coverMoney) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(coverFaultService.updateCoverFault(coverFaultId, coverFaultLevel, coverFaultType, coverFaultPhoto, coverFaultReason, coverMoney));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping("/getCoverFaultIsReport")
    @ResponseBody
    public JsonMsgDto getCoverFaultIsReport(Integer coverId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(coverFaultService.getCoverFaultIsReport(coverId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/reportCoverFault")
    @ResponseBody
    public JsonMsgDto reportCoverFault(Integer coverId, Integer coverFaultCreatorId, Integer coverFaultLevel, Integer coverFaultType,
                                         String coverFaultPhoto, String coverFaultReason, Double coverMoney, Integer coverOrgId, Integer coverMainOrgId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            coverFaultService.reportCoverFault(coverId, coverFaultCreatorId, coverFaultLevel, coverFaultType,
                    coverFaultPhoto, coverFaultReason, coverMoney, coverOrgId, coverMainOrgId);
            //为空是app端作判断
            jsonMsgDto.setJsonData("");
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/deleteCoverFaultByIds")
    @ResponseBody
    public JsonMsgDto deleteCoverFaultByIds(String coverFaultIds) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(coverFaultService.deleteCoverFaultByIds(coverFaultIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getCoverCoordinate4Map")
    @ResponseBody
    public JsonMsgDto getCoverCoordinate4Map(Integer orgId, Integer actorId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(coverFaultService.getCoverCoordinate4Map(orgId, actorId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping("/getCoverByXY")
    @ResponseBody
    public JsonMsgDto getCoverByXY(String longitude, String latitude) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(coverFaultService.getCoverByXY(longitude, latitude));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getCoverFaultReport4DT")
    @ResponseBody
    public DTResponseDto getCoverFaultReport4DT(DTRequestDto dtRequestDto, Integer actorId, Integer orgId, String coverRoadName, String coverStartRoad, String coverEndRoad) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = coverFaultService.getCoverFaultReport4DT(dtRequestDto, actorId, orgId, coverRoadName, coverStartRoad, coverEndRoad);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/getStartRoad")
    @ResponseBody
    public JsonMsgDto getStartRoad(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(coverFaultService.getStartRoad(roadName, actorId, orgId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSectionByStartRoad")
    @ResponseBody
    public JsonMsgDto getSectionByStartRoad(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(coverFaultService.getSectionByStartRoad(roadName,actorId, orgId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }


    @RequestMapping(value = "/getCoverFaultList4App")
    @ResponseBody
    public JsonMsgDto getCoverFaultList4App(Integer orgId, String actorIds, Integer faultStatus, Integer count, Integer size)
            throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(coverFaultService.getCoverFaultList4App(orgId,actorIds,faultStatus,count,size));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }
}
